package com.xmy.study.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.xmy.study.entity.ChaPlan;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ChaPlanMapper extends BaseMapper<ChaPlan> {

    @Select("SELECT c.* " +
            "FROM cha_plan c " +
            "INNER JOIN ( " +
            "    SELECT student_id, MAX(school_date) as max_school_date " +
            "    FROM cha_plan " +
            "    GROUP BY student_id " +
            ") as latest_cha_plan ON c.student_id = latest_cha_plan.student_id AND c.school_date = latest_cha_plan.max_school_date " +
            "${ew.customSqlSegment}")
    List<ChaPlan> getClearanceRateChaPlan(@Param(Constants.WRAPPER) Wrapper wrapper);
}
